<?php
namespace app\home\model;
use think\Model;
use think\Db;

class ShoppingModel extends Model{

    public function __construct(){
        parent::__construct();
    }
    //获取商城轮播个数
    public function getLimit($limit){
        $getLimit =Db::table('images_num')->where('id',2)->setField('img_num',"$limit");
        if($getLimit){
            return 1;
        }else{
            return false;
        }
    }


        // 轮播图
    public function getImages(){
        $allImages = Db::table('images')->where('is_del=0 AND status =2')->order('imgs_time desc')->count();
        $limit = Db::table('images_num')->where('id',2)->value('img_num');
//        dump($limit);
        if($allImages<=2){
            $images = Db::table('images')->where('is_del=0')->order('imgs_time desc')->limit(0,$limit)->select();
            return $images;
        }else if($allImages>=5){
            $images = Db::table('images')->where('is_del=0 AND status =2')->order('imgs_time desc')->limit(0,$limit)->select();
            return $images;
        }else{
            $images = Db::table('images')->where('is_del=0 AND status =2')->order('imgs_time desc')->limit(0,$limit)->select();
            return $images;
        }
    }


}